package top.anonyeast.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import top.anonyeast.config.interceptor.CorsInterceptor;
import top.anonyeast.config.interceptor.TokenInterceptor;

import java.util.Arrays;
import java.util.List;


/**
 * MVC配置
 *
 * @Author AnonyEast
 * @Date 2022-06-09
 * @Description
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    /**
     * 拦截器注册
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String[] staticResource = {"/css/**", "/fonts/**", "/img/**", "/js/**", "/favicon.ico", "/index.html"};
        String[] requestAllow = {"/login"};
        //添加跨域拦截器
        registry.addInterceptor(new CorsInterceptor())
                .addPathPatterns("/**");
        //添加token拦截器
        registry.addInterceptor(new TokenInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/")
                .excludePathPatterns(Arrays.asList(staticResource))
                .excludePathPatterns(Arrays.asList(requestAllow));
    }
}
